package com.rwx.reflect;

import com.rwx.reflect.model.Student;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;

public class Reflect05 {

    public static void main(String[] args) throws ClassNotFoundException,
            NoSuchMethodException,
            InvocationTargetException,
            InstantiationException, IllegalAccessException, NoSuchFieldException {


        Student s = new Student("zhangsan","23","广州");
        Student ss = new Student("lisi","24","北京");



        Class clazz=Class.forName("com.rwx.reflect.model.Student");
        Constructor con1 = clazz.getConstructor();
        Field field = clazz.getDeclaredField("name");
        field.setAccessible(true);
        field.set(s,"ww");
        String name = (String) field.get(s);
        System.out.println(name);

        System.out.println(s);
        System.out.println(ss);



    }
}
